package cn.imlql.tree;

/**
 * <p>
 * </p>
 *
 * @author youthlql
 * @since 2021/7/8 - 19:24
 */
public class _00096 {

    /**
     * <p>
     * 1.主要就是找数学公式了
     * 2.比较好的题解：
     * https://leetcode-cn.com/problems/unique-binary-search-trees/solution/bu-tong-de-er-cha-sou-suo-shu-by-leetcode-solution/
     * </p>
     *
     * @since 2021/7/9 - 16:26
     */
    public int numTrees(int n) {
        int[] G = new int[n + 1];
        G[0] = 1;
        G[1] = 1;

        for (int i = 2; i <= n; ++i) {
            for (int j = 1; j <= i; ++j) {
                G[i] += G[j - 1] * G[i - j];
            }
        }
        return G[n];
    }
}
